package com.kexio.pay.entity;

import java.time.LocalDateTime;
import java.util.Map;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kexio.common.entity.BaseEntity;

/**
 * 支付回调记录
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@TableName("pay_callback")
public class PaymentCallback extends BaseEntity {
    
    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;
    
    /**
     * 支付提供商 (wechat, alipay, unionpay)
     */
    @TableField("provider")
    private String provider;
    
    /**
     * 回调类型 (payment, refund)
     */
    @TableField("callback_type")
    private String callbackType;
    
    /**
     * 订单号
     */
    @TableField("order_no")
    private String orderNo;
    
    /**
     * 第三方订单号/退款单号
     */
    @TableField("third_party_no")
    private String thirdPartyNo;
    
    /**
     * 回调原始数据 (JSON/XML)
     */
    @TableField("callback_data")
    private String callbackData;
    
    /**
     * 回调签名
     */
    @TableField("signature")
    private String signature;
    
    /**
     * 签名验证结果
     */
    @TableField("verify_result")
    private Boolean verifyResult;
    
    /**
     * 处理结果
     */
    @TableField("process_result")
    private Boolean processResult;
    
    /**
     * 错误信息
     */
    @TableField("error_message")
    private String errorMessage;
    
    /**
     * 处理时间
     */
    @TableField("process_time")
    private LocalDateTime processTime;
    
    /**
     * 客户端IP
     */
    @TableField("client_ip")
    private String clientIp;
    
    /**
     * 用户代理
     */
    @TableField("user_agent")
    private String userAgent;
    
    /**
     * 请求头信息 (JSON格式)
     */
    @TableField("request_headers")
    private String requestHeaders;
    
    /**
     * 响应内容
     */
    @TableField("response_content")
    private String responseContent;
    
    /**
     * 响应状态码
     */
    @TableField("response_status")
    private Integer responseStatus;
    
    /**
     * 处理耗时 (毫秒)
     */
    @TableField("process_duration")
    private Long processDuration;
    
    /**
     * 回调参数Map (非数据库字段)
     */
    @TableField(exist = false)
    private Map<String, String[]> callbackParams;
    
    // Constructors
    public PaymentCallback() {}
    
    /**
     * 构造函数（用于回调处理）
     */
    public PaymentCallback(String provider, Map<String, String[]> callbackParams) {
        this.provider = provider;
        this.callbackParams = callbackParams;
        this.callbackType = "payment";
        this.verifyResult = false;
        this.processResult = false;
    }
    
    public PaymentCallback(String provider, String callbackType, String orderNo, 
                          String callbackData, String signature) {
        this.provider = provider;
        this.callbackType = callbackType;
        this.orderNo = orderNo;
        this.callbackData = callbackData;
        this.signature = signature;
        this.verifyResult = false;
        this.processResult = false;
    }
    
    // Getters and Setters
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    
    public String getProvider() { return provider; }
    public void setProvider(String provider) { this.provider = provider; }
    
    public String getCallbackType() { return callbackType; }
    public void setCallbackType(String callbackType) { this.callbackType = callbackType; }
    
    public String getOrderNo() { return orderNo; }
    public void setOrderNo(String orderNo) { this.orderNo = orderNo; }
    
    public String getThirdPartyNo() { return thirdPartyNo; }
    public void setThirdPartyNo(String thirdPartyNo) { this.thirdPartyNo = thirdPartyNo; }
    
    public String getCallbackData() { return callbackData; }
    public void setCallbackData(String callbackData) { this.callbackData = callbackData; }
    
    public String getSignature() { return signature; }
    public void setSignature(String signature) { this.signature = signature; }
    
    public Boolean getVerifyResult() { return verifyResult; }
    public void setVerifyResult(Boolean verifyResult) { this.verifyResult = verifyResult; }
    
    public Boolean getProcessResult() { return processResult; }
    public void setProcessResult(Boolean processResult) { this.processResult = processResult; }
    
    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    
    public LocalDateTime getProcessTime() { return processTime; }
    public void setProcessTime(LocalDateTime processTime) { this.processTime = processTime; }
    
    public String getClientIp() { return clientIp; }
    public void setClientIp(String clientIp) { this.clientIp = clientIp; }
    
    public String getUserAgent() { return userAgent; }
    public void setUserAgent(String userAgent) { this.userAgent = userAgent; }
    
    public String getRequestHeaders() { return requestHeaders; }
    public void setRequestHeaders(String requestHeaders) { this.requestHeaders = requestHeaders; }
    
    public String getResponseContent() { return responseContent; }
    public void setResponseContent(String responseContent) { this.responseContent = responseContent; }
    
    public Integer getResponseStatus() { return responseStatus; }
    public void setResponseStatus(Integer responseStatus) { this.responseStatus = responseStatus; }
    
    public Long getProcessDuration() { return processDuration; }
    public void setProcessDuration(Long processDuration) { this.processDuration = processDuration; }
    
    public Map<String, String[]> getCallbackParams() { return callbackParams; }
    public void setCallbackParams(Map<String, String[]> callbackParams) { this.callbackParams = callbackParams; }
}
